#include "virtualmachine.h"

VirtualMachine::VirtualMachine(int pager):Process()
{
    name = "VirtualMachine";
    VirtualMachineState = new ProcessorContainer();
    Word temp;
    temp[0] = 0x00;
    temp[1] = 0x00;
    DByte temp2;
    temp2[0] = 0x00;
    temp2[1] = 0x00;
    temp2[2] = 0x00;
    temp2[3] = 0x00;
    VirtualMachineState->setIO(temp);
    VirtualMachineState->setMODE(0);
    VirtualMachineState->setNEXT(temp);
    VirtualMachineState->setTIME(9);
    VirtualMachineState->setPPR(0);
    VirtualMachineState->setRA(temp);
    VirtualMachineState->setRB(temp);
    VirtualMachineState->setSF(0);
    VirtualMachineState->setSPR(temp2);
    temp2[0] = pager;
    VirtualMachineState->setPL(temp2);
}

VirtualMachine::~VirtualMachine()
{
    delete(VirtualMachineState);
}

void VirtualMachine::Run() {
    LogManager::getSingleton().Message("VirtualMachine", "step "+LogManager::getSingleton().toStr(currentStep));
    switch(currentStep){
    case 0:{
        RealMachine::getSingleton().LoadProcessor(VirtualMachineState);
    }
    break;
    case 1:{
        RealMachine::getSingleton().UnloadProcessor(VirtualMachineState);
        ResourceAllocator::getSingleton().addResource(new InteruptResource(id));
    }
    break;
    case 2:{
       // ResourceAllocator::getSingleton().askForResource("");
         currentStep=-1;

    }
    break;
    default:
      qDebug() << "gg VirtualMachine";
    }
    currentStep++;
}
